import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:provide/provide.dart';

import '../config/index.dart';
import '../provide/current_index_provide.dart';
import 'course_page.dart';
import 'home_page.dart';
import 'member_page.dart';


class IndexPage extends StatelessWidget{

  final List<BottomNavigationBarItem> bottomTabs = [
    BottomNavigationBarItem(
      icon: Icon(Icons.home),
      title: Text(KString.homeTitle), // 首页
    ),
    BottomNavigationBarItem(
      icon: Icon(Icons.all_inclusive),
      title: Text(KString.courseTitle), // 课程
    ),
//    BottomNavigationBarItem(
//      icon: Icon(Icons.add_alert),
//      title: Text(KString.questionTitle), // 题库
//    ),
//    BottomNavigationBarItem(
//      icon: Icon(Icons.add_alert),
//      title: Text(KString.examinationPaperTitle), // 试卷
//    ),
    BottomNavigationBarItem(
      icon: Icon(Icons.person),
      title: Text(KString.myTitle), // 我的
    ),
  ];

  final List<Widget> tabBodies = [
    HomePage(),
    CoursePage(),
    MemberPage()
  ];
  @override
  Widget build(BuildContext context) {
    // 初始化屏幕适配
    ScreenUtil.instance = ScreenUtil(width: 750, height: 1334)..init(context);
    return Provide<CurrentIndexProvide>(
      builder: (context, child, val){
        // 取到当前索引状态值
        int currentIndex = Provide.value<CurrentIndexProvide>(context).currentIndex;
        return Scaffold(
          bottomNavigationBar: BottomNavigationBar(
            selectedItemColor: KColor.buttonShowBackGroundColor,
            type: BottomNavigationBarType.fixed,
            currentIndex: currentIndex,
            items: bottomTabs,
            onTap: (index){
              Provide.value<CurrentIndexProvide>(context).changIndex(index);
            },
          ),
          body: IndexedStack(
            index: currentIndex,
            children: tabBodies,
          ),
        );
      },
    );
  }

}